
   u  t            D e f a u l t                                                                                                    u              S A _ P l a n t M o d e l P i c k e r                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   m*^:F-]*	n4'K cVRn                 S A _ P l a n t M o d e l P i c k e r                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       $ S y m b o l                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       $ S y m b o l                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                "   L i n e a _ P r o d u c c i o n                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       t                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            S A _ P l a n t M o d e l P i c k e r                                                         UQ K_ UQ K_ UQ K_ UQ K_    e  UQ K_      	     R e p r e s e n t s   a   u s e r - c o n f i g u r e d   S y m b o l   u s e d   t o   s h o w   p r o c e s s   g r a p h i c s   h  UQ K_ j  UQ K_      D e f a u l t   k  UQ K_ r  UQ K_
      E n a b l e      p s  UQ K_ u  UQ K_        v  UQ K_ w  UQ K_        x  UQ K_        y  UQ K_        z  UQ K_        {  UQ K_        |  UQ K_
(      E n g i n e P l a t f o r m      f ~  UQ K_   UQ K_P                (   S A _ P l a n t M o d e l P i c k e r                       UQ K_
   
   N o n e      l   UQ K_      UQ K_          UQ K_          UQ K_          UQ K_          UQ K_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       d        t                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            S A _ P l a n t M o d e l P i c k e r                                                         UQ K_ UQ K_ UQ K_ UQ K_ 	    d UQ K_         d UQ K_      S y m b o l   d d UQ K_	       e d UQ K_        f d UQ K_         
        g d UQ K_ h d UQ K_ i d UQ K_	       j d UQ K_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       e d       t                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        a  S A _ P l a n t M o d e l P i c k e r                                                         UQ K_ UQ K_ UQ K_ UQ K_ 
    e UQ K_         e UQ K_       V i s u a l E l e m e n t   d e UQ K_        e e UQ K_      S y m b o l   f e UQ K_  y  PNG

   
IHDR   d   `   sB   sRGB    gAMA  a   	pHYs    od  IDATx^ѱ
0APz6p5|fm/u]a#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1#H 1 lf
U>    IENDB`g e UQ K_ h e UQ K_E        7   2   .   C l i e n t C o n t r o l : T r e e V i e w   i e UQ K_B           j e UQ K_    2    C      ?         d          _populateTreeView       _initialized      e                 
System.String Kmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089        	              
System.Object System.String ToString()        Microsoft.Win32.RegistryKey %System.Object GetValue(System.String)           5Microsoft.Win32.RegistryKey OpenSubKey(System.String) "       Microsoft.Win32.Registry (Microsoft.Win32.RegistryKey LocalMachine          SOFTWARE\ArchestrA\Framework          RootPath           
_fullFileName    lArchestrA.QuickScript.QuickScriptCompiler, Version=1.1.0.0, Culture=neutral, PublicKeyToken=23106a86e706d0ae *ArchestrA.QuickScript.Runtime.QuickConvert %System.String ToString(System.Object)                     "\GlobalDataCache\AreaHierarchy.xml       _areaIconFileName      
                           \Icons\area.w2k.bmp       _appEngineIconFileName      
                           \Icons\appengine.w2k.bmp       _grWinPlatformIconFileName      
                           \Icons\GRNode.w2k.bmp       _winPlatformIconFileName      
                           \Icons\ntplatform.w2k.bmp       _initialized       e                 
System.String Kmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089        	              System.DateTime System.String ToString()        System.IO.File /System.DateTime GetLastWriteTime(System.String)       
_fullFileName          
               _lastWriteTime                _populateTreeView                               e                PopulateTreeViewOnDemand               _populateTreeView       e      C           System.IO.FileStream Kmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089               
System.Byte[]                   System.IO.MemoryStream                  System.IO.BinaryReader                  System.Int32           	       #           CVoid .ctor(System.String, System.IO.FileMode, System.IO.FileAccess)       
_fullFileName   "       System.IO.FileMode System.IO.FileMode Open"       System.IO.FileAccess System.IO.FileAccess Read               Int32 Read(Byte[], Int32, Int32)                                 lArchestrA.QuickScript.QuickScriptCompiler, Version=1.1.0.0, Culture=neutral, PublicKeyToken=23106a86e706d0ae *ArchestrA.QuickScript.Runtime.QuickConvert Int32 ToInt32(Double)      
       Double ToDouble(Int64)              Int64 get_Length()             	         
               
                                                    Void Close()             	      #           Void .ctor(Byte[], Int32, Int32)                           	      #          Void .ctor(System.IO.Stream)                                     
System.Char[]                    
System.String           	                                            'Int64 Seek(Int64, System.IO.SeekOrigin)              
       Int64 ToInt64(Double)      
       Double ToDouble(Int32)          "       System.IO.SeekOrigin System.IO.SeekOrigin Begin              Int32 Read(Char[], Int32, Int32)                                     	      #          Void .ctor(Char[])          	          IQuickScriptLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null ArchestrA.QuickScript.Functions .System.String StringLeft(System.String, Int32)                      	             System.String ToUpper()                   <ROO                 	         
                               	         
       Int32 ToInt32(System.Object)                                                                  
               
                   "                                                                                  	      #                                                                     	    System.Xml.XPath.XPathNavigator MSystem.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089           
    System.Xml.XPath.XPathDocument%                  "System.Xml.XPath.XPathNodeIterator%                  System.Windows.Forms.ImageList WSystem.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089           
    System.Drawing.Image QSystem.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a              *   +                 *   +                 *   +                  System.Windows.Forms.TreeNode)                 ,   )                 ,   )                 ,   )                 ,   )                 ,   )                 ,   )                 ,   )                 ,   )                 ,   )                 ,   )                 ,   )                                      System.Boolean           	   
   #   %   &                	   	      %   &    1System.Xml.XPath.XPathNavigator CreateNavigator()     
       	      #   )   (    Void .ctor()          )    .System.Windows.Forms.ImageList+ImageCollection Void Clear()    )   (    ImageCollection get_Images()                	   
      +   *    ,System.Drawing.Image FromFile(System.String)       _areaIconFileName   	         +   *   3          _appEngineIconFileName   	         +   *   3          _grWinPlatformIconFileName   	         +   *   3          _winPlatformIconFileName         )   (    /Void set_TransparentColor(System.Drawing.Color)              +    System.Drawing.Color "System.Drawing.Color get_Fuchsia()          )   0    -Void Add(System.String, System.Drawing.Image)    )   (   2                         areaIcon    
         )   0   ;       )   (   2                         
appEngineIcon             )   0   ;       )   (   2                         GRWinPlatformIcon             )   0   ;       )   (   2                         WinPlatformIcon             )    System.Windows.Forms.TreeView 2Void set_ImageList(System.Windows.Forms.ImageList)        gPlantAreas                   )   @    Void BeginUpdate()       B                   )    'System.Windows.Forms.TreeNodeCollection Int32 get_Count()    )   @    3System.Windows.Forms.TreeNodeCollection get_Nodes()       B                                    )   D   1       )   @   F          B                     	             //Area[@IsArea='1']	         %   $    8System.Xml.XPath.XPathNodeIterator Select(System.String)     	                   %   '    Boolean MoveNext()                                                              !                    "                 	          %   $    8System.String GetAttribute(System.String, System.String)    %   '    -System.Xml.XPath.XPathNavigator get_Current()                      Name        	   !      %   $   J       %   '   K                         Category      M   	   "      %   $   J       %   '   K                         
PlatformID      M   	   	      %   '   K                     %   $    Boolean MoveToParent()     	       	         %   $   J        	            L         M   	                 	      %   $   J        	            L         M         M         	      #   )   ,    'Void .ctor(System.String, Int32, Int32)                                     )   D    (Int32 Add(System.Windows.Forms.TreeNode)    )   @   F          B                          
       DefaultSelectedName         M   	              S                  )   @    4Void set_SelectedNode(System.Windows.Forms.TreeNode)       B                      )   @    Boolean Focus()       B                                )   @   F          B                   	                                     	      )   ,    System.String get_Text()                            	       !          3      	      #   )   ,   Q                                         	       !          1         	       "         X         	      #   )   ,   Q                                      	      #   )   ,   Q                                      	      #   )   ,   Q                                        )   D   R       )   ,   F                               
      S            M   	              S                  )   @   T          B                      )   @   U          B                 	                                )   ,   F                        	      )   ,   V                               	       !         W         	      #   )   ,   Q                                         	       !         X            	       "         X         	      #   )   ,   Q                                      	      #   )   ,   Q                                      	      #   )   ,   Q                                        )   D   R       )   ,   F                               
      S            M   	              S                  )   @   T          B                      )   @   U          B                 	                                )   ,   F                        	      )   ,   V                               	       !         W         	      #   )   ,   Q                                         	       !         X            	       "         X         	      #   )   ,   Q                                      	      #   )   ,   Q                                      	      #   )   ,   Q                                        )   D   R       )   ,   F                               
      S            M   	              S                  )   @   T          B                      )   @   U          B                 	                                )   ,   F                        	      )   ,   V                               	       !         W         	      #   )   ,   Q                                         	       !         X            	       "         X         	      #   )   ,   Q                                      	      #   )   ,   Q                                      	      #   )   ,   Q                                        )   D   R       )   ,   F                               
      S            M   	              S                  )   @   T          B                      )   @   U          B                 	                                )   ,   F                        	      )   ,   V                               	       !         W         	      #   )   ,   Q                                         	       !         X            	       "         X         	      #   )   ,   Q                                      	      #   )   ,   Q                                      	      #   )   ,   Q                                        )   D   R       )   ,   F                               
      S            M   	              S                  )   @   T          B                      )   @   U          B                 	                                )   ,   F                        	      )   ,   V                               	       !         W         	      #   )   ,   Q                                         	       !         X            	       "         X         	      #   )   ,   Q                                      	      #   )   ,   Q                                      	      #   )   ,   Q                                        )   D   R       )   ,   F                               
      S            M   	              S                  )   @   T          B                      )   @   U          B                 	                                )   ,   F                        	      )   ,   V                               	       !         W         	      #   )   ,   Q                                         	       !         X            	       "         X         	      #   )   ,   Q                                      	      #   )   ,   Q                                      	      #   )   ,   Q                                        )   D   R       )   ,   F                               
      S            M   	              S                  )   @   T          B                      )   @   U          B                 	                                )   ,   F                        	      )   ,   V                               	       !         W         	      #   )   ,   Q                                         	       !         X            	       "         X         	      #   )   ,   Q                                      	      #   )   ,   Q                                      	      #   )   ,   Q                                        )   D   R       )   ,   F                               
      S            M   	              S                  )   @   T          B                      )   @   U          B                 	                                )   ,   F                        	      )   ,   V                               	       !         W         	      #   )   ,   Q                                         	       !         X            	       "         X         	      #   )   ,   Q                                      	      #   )   ,   Q                                      	      #   )   ,   Q                                        )   D   R       )   ,   F                               
      S            M   	              S                  )   @   T          B                      )   @   U          B                 	                              )   @    Void ExpandAll()       B                )   @    Void EndUpdate()       B                 _lastWriteTime       System.DateTime System.String ToString()        System.IO.File /System.DateTime GetLastWriteTime(System.String)                       _populateTreeView        e                 System.Windows.Forms.TreeNode WSystem.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089                     'System.Windows.Forms.TreeNodeCollection Int32 get_Count()        System.Windows.Forms.TreeView 3System.Windows.Forms.TreeNodeCollection get_Nodes()                               	                 5System.Windows.Forms.TreeNode GetNodeAt(Int32, Int32)                 #System.Windows.Forms.MouseEventArgs 
Int32 get_X()     e              
Int32 get_Y()    	          
                           SelectedName           System.String get_Text()                                                       Arial  @A                _populateTreeView   T'ХHq@
v   T'ХHq@
v      False               O{Internal} Will trigger script to build and add nodes to the TreeView control. PopulateTreeView   SelectedName   %by-!L_c.   %by-!L_c.                      U{OUTPUT} Allows the user to get the text of the selected node in the TreeView controlSelectedNodeName   _lastWriteTime   *Ic")G   *Ic")G                      D{Internal} Maintains value of AreaHierarchy.xml last file write time
LastWriteTime   
_fullFileName   d 1A1ӡ   d 1A1ӡ                      +{Internal} Holds path of AreaHierarchy.xml FullFileName   _areaIconFileName   ~l =fO
s   ~l =fO
s                      %{Internal} Holds path to A2 Area iconAreaIconFileName   _fileWatcherCheck   f\4Hvd   f\4Hvd      True              P{Internal} Allows the Area Picker to check the AreaHierarchy.xml for any changesFileWatcherCheck   _appEngineIconFileName   .Gh#p.   .Gh#p.                      *{Internal} Holds path to A2 AppEngine iconAppEngineIconFileName   _winPlatformIconFileName   D5FٷvBu   D5FٷvBu                      ,{Internal} Holds path to A2 WinPlatform iconWinPlatformIconFileName   _grWinPlatformIconFileName   Ú9D*
haP   Ú9D*
haP                      .{Internal} Holds path to A2 GRWinPlatform iconGRWinPlatformIconFileName   DefaultSelectedName   ;&ZJX#`h^   ﬡ?DٳK                      /{INPUT} Set the default tree selected node name    PopulateTreeViewOnDemand   $
b'Ko(]a   TlNҽz#@      false               s{INPUT\OUTPUT} Set to true will trigger the populate of the tree view. The symbol will reset to false on execusion.    _initialized   _^OX%YԏI   @wW(I|`      False               #{Internal} Flag control initialized          2.0.50727.42 (RTM.050727-4200)ClientControl:TreeView      A  A  C  C   A  A  C  C   gPlantAreas                                                    Y@      Y@         Arial  @A                                                                MouseUp          dim m_tNode as System.Windows.Forms.TreeNode;

if (Nodes.Count > 0) then
	m_tNode = GetNodeAt(e.X,e.Y);
	
	if (m_tNode <> null) then
		SelectedName = m_tNode.Text;	
	Endif;
endif;      Nodes.Count    SelectedName         
System.ObjectKmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089sendersender#System.Windows.Forms.MouseEventArgsWSystem.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089ee  E  PNG

   
IHDR  ,  "   Cw   gAMA  a   	pHYs    rI  IDATx^	0A=|d3PC&לs7X , C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, C2, 13;y;Xo	~*    IENDB`        DrawModeNormal%System.Windows.Forms.TreeViewDrawModeWSystem.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089            SelectedImageKey               RightToLeftLayoutFalse              
ScrollableTrue              BorderStyleFixed3D System.Windows.Forms.BorderStyleWSystem.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089            
PathSeparator\              
ImageIndex-1              
ShowPlusMinusTrue              SelectedImageIndex-1              
FullRowSelectTrue              
ShowRootLinesTrue              ShowNodeToolTipsFalse              
HideSelectionFalse              	ShowLinesTrue              	LabelEditFalse              	ImageList      	ImageSize      Width               Height                       
ColorDepth                       ImageKey               
ItemHeight20              StateImageList      	ImageSize      Width               Height                       
ColorDepth                       
CheckBoxesFalse              HotTrackingFalse              Indent20                                                	{*************************************************************************************
-- Procedure Name :     Plant Area Picker On Show script 
-- Purpose        :     Initialize XML and Icon paths and build Area Picker Tree 
-- Location       :     $PlantAreaPicker
-- Author         :     Nick Santucci (Wonderware Solution Architect)
				Eric Enet (Wonderware Consulting Instructor)
-- Date           :     07/30/07 
-- Last Modified  :     07/30/07
-- Version        :     1.0.0
**************************************************************************************}

Dim aaRootPath As String; ' Holds the ArchestrA root path 

' Get the Path for the Plant Model XML and A2 Icons
aaRootPath = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ArchestrA\Framework" ).GetValue("RootPath").ToString();
_fullFileName = aaRootPath + "\GlobalDataCache\AreaHierarchy.xml";
_areaIconFileName = aaRootPath + "\Icons\area.w2k.bmp";
_appEngineIconFileName = aaRootPath + "\Icons\appengine.w2k.bmp";
_grWinPlatformIconFileName = aaRootPath + "\Icons\GRNode.w2k.bmp";
_winPlatformIconFileName = aaRootPath + "\Icons\ntplatform.w2k.bmp";

_initialized=true;

' Build the TreeView for first time
'_populateTreeView = true;



       
_fullFileName    _areaIconFileName   _appEngineIconFileName   _grWinPlatformIconFileName   _winPlatformIconFileName   _initialized                                             FileWatcher_fileWatcherCheck            _fileWatcherCheck             {*************************************************************************************
-- Procedure Name :     Plant Area Picker FileWatcher script 
-- Purpose        :     Check if AreaHierarchy.xml has changed, if so rebuild Area Picker Tree  
-- Location       :     $PlantAreaPicker
-- Author         :     Nick Santucci (Wonderware Solution Architect)
				Eric Enet (Wonderware Consulting Instructor)
-- Date           :     07/30/07 
-- Last Modified  :     07/30/07
-- Version        :     1.0.0
**************************************************************************************}

Dim writeTime As String;

writeTime = System.IO.File.GetLastWriteTime(_fullFileName).ToString();

If (writeTime <> _lastWriteTime) Then
	_populateTreeView = true; ' Rebuild TreeView Control
	_lastWriteTime = writeTime;	
EndIf;

      
_fullFileName    _lastWriteTime   _populateTreeView              OnDemandTriggerPopulateTreeViewOnDemand            PopulateTreeViewOnDemand            :PopulateTreeViewOnDemand=false;
_populateTreeView=true;
      PopulateTreeViewOnDemand    _populateTreeView              PopulateTreeViewControl"_populateTreeView and _initialized                 _populateTreeView    _initialized             u{*************************************************************************************
-- Procedure Name :     Plant Area Picker PopulateTreeViewControl script 
-- Purpose        :     Build the Area Picker Tree based on AreaHierarchy.xml and A2 Area Icon   
-- Location       :     $PlantAreaPicker
-- Author         :     Nick Santucci (Wonderware Solution Architect)
				Eric Enet (Wonderware Consulting Instructor)
-- Date           :     07/30/07 
-- Last Modified  :     07/30/07
-- Version        :     1.0.0
**************************************************************************************}

Dim fs As System.IO.FileStream;
Dim streamBuffer[102400] As System.Byte; 'Holds 100Kb.
Dim ms As System.IO.MemoryStream;
Dim streamReader As System.IO.BinaryReader;
Dim length As Integer;

' Load the file.
fs = new System.IO.FileStream (_fullFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); 
' Transfer the file to a byte array buffer.
fs.Read(streamBuffer[], 0, fs.Length);
length = fs.Length; 'Needed to cast a long into an integer 

fs.Close();
' Load the memory stream with the buffer.
ms = new System.IO.MemoryStream(streamBuffer[], 0, length);
' Create the reader for the memory stream.
streamReader = new System.IO.BinaryReader(ms);
 
{
	Locate the beginning of the xml code within the file.
	The file has some binary data as a header that prevents
	the .Net xml classes to load it.
}

Dim offset As Integer; 'Offset where the xml code starts
Dim headerBuffer[5] As System.Char;
Dim valueRead As String; 'Holds the string representation of the buffer

offset = 23; 
 
' Locate the beginning of the xml code.
While (True) 		
	
	ms.Seek(offset, System.IO.SeekOrigin.Begin);	
	streamReader.Read(headerBuffer[], 0, 4);	
	valueRead = new System.String(headerBuffer[]);

	valueRead = StringLeft(valueRead,4);
	 
	If (valueRead.ToUpper() == "<ROO") Then
		Exit While;
	EndIf;
	 
	offset = offset + 1;
EndWhile; 
 
{
	Transfer the xml code from the memory (file) stream
	to a new memory (xml) stream.
	The following code uses the streamBuffer and length
	variables declared above.
}
 
length = ms.Length - offset;
ms.Seek(offset, System.IO.SeekOrigin.Begin);
ms.Read(streamBuffer[], 0, length);
Dim xmlStream As System.IO.MemoryStream;
xmlStream = new System.IO.MemoryStream(streamBuffer[], 0, length);
ms.Close();

' Declare XML variables
Dim nav as System.Xml.XPath.XPathNavigator; 
Dim docNav as System.Xml.XPath.XPathDocument;
Dim nodeIter as System.Xml.XPath.XPathNodeIterator;

' Declare ImageList variables
Dim imageList as System.Windows.Forms.ImageList;
Dim areaImage as System.Drawing.Image;
Dim appEngineImage as System.Drawing.Image;
Dim winPlatformImage as System.Drawing.Image;
Dim grWinPlatformImage as System.Drawing.Image;


' Declare Treeview variables
Dim tRootNode as System.Windows.Forms.TreeNode;
Dim tSecondLevelNode as System.Windows.Forms.TreeNode;
Dim tThirdLevelNode as System.Windows.Forms.TreeNode;
Dim tFourthLevelNode as System.Windows.Forms.TreeNode;
Dim tFifthLevelNode as System.Windows.Forms.TreeNode;
Dim tSixthLevelNode as System.Windows.Forms.TreeNode;
Dim tSeventhLevelNode as System.Windows.Forms.TreeNode;
Dim tEigthLevelNode as System.Windows.Forms.TreeNode;
Dim tNinethLevelNode as System.Windows.Forms.TreeNode;
Dim tTenthLevelNode as System.Windows.Forms.TreeNode;
Dim tChildNode as System.Windows.Forms.TreeNode;
dim tNodeIter as System.Windows.Forms.TreeNode;

Dim strExpression as System.String;
Dim bNodeFound as Boolean;

' Load the Plant Model XMl file into XPath
docNav = new System.Xml.XPath.XPathDocument(xmlStream);
nav = docNav.CreateNavigator();

' Set up image list
imageList = New System.Windows.Forms.ImageList;

imageList.Images.Clear();

areaImage = System.Drawing.Image.FromFile(_areaIconFileName);
appEngineImage = System.Drawing.Image.FromFile(_appEngineIconFileName);
grWinPlatformImage = System.Drawing.Image.FromFile(_grWinPlatformIconFileName);
winPlatformImage = System.Drawing.Image.FromFile(_winPlatformIconFileName);

imageList.TransparentColor = System.Drawing.Color.Fuchsia;

' Area Icon is index 0
' AppEngine Icon index 1
' GRWinPlatform Icon index 2
' WinPlatform (non-GR) Icon index 3

imageList.Images.Add("areaIcon", areaImage);
imageList.Images.Add("appEngineIcon", appEngineImage);
imageList.Images.Add("GRWinPlatformIcon", grWinPlatformImage);
imageList.Images.Add("WinPlatformIcon", winPlatformImage);


' Set the ImageList to the TreeView Control
gPlantAreas.ImageList = imageList; 

' Begin adding the Plant Area Nodes to the TreeView Control
gPlantAreas.BeginUpdate();

if gPlantAreas.Nodes.Count > 0 then
	gPlantAreas.Nodes.Clear();
endif;

' Query for the Area Nodes
strExpression = "//Area[@IsArea='1']";

' Select the node and place the results in an iterator.
NodeIter = nav.Select(strExpression);

' Iterate through the results showing the element value.
while (NodeIter.MoveNext()) 	     

	Dim parentName as System.String;
	Dim areaName as System.String;
	Dim areaCategory as System.String;
	Dim areaPlatformID as System.String;
	
	areaName = NodeIter.Current.GetAttribute("Name","");
	
	areaCategory = NodeIter.Current.GetAttribute("Category","");
	
	areaPlatformID = NodeIter.Current.GetAttribute("PlatformID","");	

	nav = NodeIter.Current;

	nav.MoveToParent(); 'Get the Area's Parent

	parentName = nav.GetAttribute("Name","");	

	bNodeFound = false; ' Used to exit the nested for each loops if target area is found and added

	'IAS does not support function recursion, but luckily we know it only allows 9 levels of nesting
	'in the Plant Model
	
	if (nav.GetAttribute("Name","") == "") then 
		tRootNode = new System.Windows.Forms.TreeNode(areaName,0,0);
		gPlantAreas.Nodes.Add(tRootNode);		
		if DefaultSelectedName<>"" and areaName==DefaultSelectedName then
			gPlantAreas.SelectedNode=tRootNode;
			gPlantAreas.focus();
		endif;	
	else
		'Check if Root Node (1st level) is Parent, if not then search each plant model level up to 9
		For Each tNodeIter In gPlantAreas.Nodes

			if (bNodeFound == true) then
				Exit For;
			Endif;

			if (tNodeIter.Text == parentName) then
				if (AreaCategory == "3") then
					tChildNode = new System.Windows.Forms.TreeNode(areaName,1,1);
				else if (areaCategory == "1") then
					if (areaPlatformID == "1") then
						tChildNode = new System.Windows.Forms.TreeNode(areaName,2,2);
					else
						tChildNode = new System.Windows.Forms.TreeNode(areaName,3,3);
					endif;
				else
					tChildNode = new System.Windows.Forms.TreeNode(areaName,0,0);
				endif;
				endif;

				tNodeIter.Nodes.Add(tChildNode);
				if DefaultSelectedName<>"" and areaName==DefaultSelectedName then
					gPlantAreas.SelectedNode=tChildNode;
					gPlantAreas.focus();
				endif;	
				bNodeFound = true;
				Exit For;
			else
				For Each tSecondLevelNode in tNodeIter.Nodes
					if (tSecondLevelNode.Text == parentName) then
						if (areaCategory == "3") then
							tChildNode = new System.Windows.Forms.TreeNode(areaName,1,1);
						else if (areaCategory == "1") then
							if (areaPlatformID == "1") then
								tChildNode = new System.Windows.Forms.TreeNode(areaName,2,2);
							else
								tChildNode = new System.Windows.Forms.TreeNode(areaName,3,3);
							endif;
						else
							tChildNode = new System.Windows.Forms.TreeNode(areaName,0,0);
						endif;
						endif;

						tSecondLevelNode.Nodes.Add(tChildNode);
						if DefaultSelectedName<>"" and areaName==DefaultSelectedName then
							gPlantAreas.SelectedNode=tChildNode;
							gPlantAreas.focus();
						endif;	
						bNodeFound = true;
						Exit For;
					else
						For Each tThirdLevelNode in tSecondLevelNode.Nodes
							if (tThirdLevelNode.Text == parentName) then
								if (areaCategory == "3") then
									tChildNode = new System.Windows.Forms.TreeNode(areaName,1,1);
								else if (areaCategory == "1") then
									if (areaPlatformID == "1") then
										tChildNode = new System.Windows.Forms.TreeNode(areaName,2,2);
									else
										tChildNode = new System.Windows.Forms.TreeNode(areaName,3,3);
									endif;
								else
									tChildNode = new System.Windows.Forms.TreeNode(areaName,0,0);
								endif;
								endif;

								tThirdLevelNode.Nodes.Add(tChildNode);
								if DefaultSelectedName<>"" and areaName==DefaultSelectedName then
									gPlantAreas.SelectedNode=tChildNode;
									gPlantAreas.focus();
								endif;	
								bNodeFound = true;
								Exit For;
							else
								For Each tFourthLevelNode in tThirdLevelNode.Nodes
									if (tFourthLevelNode.Text == parentName) then
										if (areaCategory == "3") then
											tChildNode = new System.Windows.Forms.TreeNode(areaName,1,1);
										else if (areaCategory == "1") then
											if (areaPlatformID == "1") then
												tChildNode = new System.Windows.Forms.TreeNode(areaName,2,2);
											else
												tChildNode = new System.Windows.Forms.TreeNode(areaName,3,3);
											endif;
										else
											tChildNode = new System.Windows.Forms.TreeNode(areaName,0,0);
										endif;
										endif;

										tFourthLevelNode.Nodes.Add(tChildNode);
										if DefaultSelectedName<>"" and areaName==DefaultSelectedName then
											gPlantAreas.SelectedNode=tChildNode;
											gPlantAreas.focus();
										endif;	
										bNodeFound = true;
										Exit For;
									else
										For Each tFifthLevelNode in tFourthLevelNode.Nodes
											if (tFifthLevelNode.Text == parentName) then
												if (areaCategory == "3") then
													tChildNode = new System.Windows.Forms.TreeNode(areaName,1,1);
												else if (areaCategory == "1") then
													if (areaPlatformID == "1") then
														tChildNode = new System.Windows.Forms.TreeNode(areaName,2,2);
													else
														tChildNode = new System.Windows.Forms.TreeNode(areaName,3,3);
													endif;
												else
													tChildNode = new System.Windows.Forms.TreeNode(areaName,0,0);
												endif;
												endif;

												tFifthLevelNode.Nodes.Add(tChildNode);
												if DefaultSelectedName<>"" and areaName==DefaultSelectedName then
													gPlantAreas.SelectedNode=tChildNode;
													gPlantAreas.focus();
												endif;	
												bNodeFound = true;
												Exit For;
											else
												For Each tSixthLevelNode in tFifthLevelNode.Nodes
													if (tSixthLevelNode.Text == parentName) then
														if (areaCategory == "3") then
															tChildNode = new System.Windows.Forms.TreeNode(areaName,1,1);
														else if (areaCategory == "1") then
															if (areaPlatformID == "1") then
																tChildNode = new System.Windows.Forms.TreeNode(areaName,2,2);
															else
																tChildNode = new System.Windows.Forms.TreeNode(areaName,3,3);
															endif;
														else
															tChildNode = new System.Windows.Forms.TreeNode(areaName,0,0);
														endif;
														endif;

														tSixthLevelNode.Nodes.Add(tChildNode);
														if DefaultSelectedName<>"" and areaName==DefaultSelectedName then
															gPlantAreas.SelectedNode=tChildNode;
															gPlantAreas.focus();
														endif;	
														bNodeFound = true;
														Exit For;
													else
														For Each tSeventhLevelNode in tSixthLevelNode.Nodes
															if (tSeventhLevelNode.Text == parentName) then
																if (areaCategory == "3") then
																	tChildNode = new System.Windows.Forms.TreeNode(areaName,1,1);
																else if (areaCategory == "1") then
																	if (areaPlatformID == "1") then
																		tChildNode = new System.Windows.Forms.TreeNode(areaName,2,2);
																	else
																		tChildNode = new System.Windows.Forms.TreeNode(areaName,3,3);
																	endif;
																else
																	tChildNode = new System.Windows.Forms.TreeNode(areaName,0,0);
																endif;
																endif;

																tSeventhLevelNode.Nodes.Add(tChildNode);
																if DefaultSelectedName<>"" and areaName==DefaultSelectedName then
																	gPlantAreas.SelectedNode=tChildNode;
																	gPlantAreas.focus();
																endif;	
																bNodeFound = true;
																Exit For;
															else
																For Each tEigthLevelNode in tSeventhLevelNode.Nodes
																	if (tEigthLevelNode.Text == parentName) then
																		if (areaCategory == "3") then
																			tChildNode = new System.Windows.Forms.TreeNode(areaName,1,1);
																		else if (areaCategory == "1") then
																			if (areaPlatformID == "1") then
																				tChildNode = new System.Windows.Forms.TreeNode(areaName,2,2);
																			else
																				tChildNode = new System.Windows.Forms.TreeNode(areaName,3,3);
																			endif;
																		else
																			tChildNode = new System.Windows.Forms.TreeNode(areaName,0,0);
																		endif;
																		endif;

																		tEigthLevelNode.Nodes.Add(tChildNode);
																		if DefaultSelectedName<>"" and areaName==DefaultSelectedName then
																			gPlantAreas.SelectedNode=tChildNode;
																			gPlantAreas.focus();
																		endif;	
																		bNodeFound = true;
																		Exit For;
																	else
																		For Each tNinethLevelNode in tEigthLevelNode.Nodes
																			if (tNinethLevelNode.Text == parentName) then
																				if (areaCategory == "3") then
																					tChildNode = new System.Windows.Forms.TreeNode(areaName,1,1);
																				else if (areaCategory == "1") then
																					if (areaPlatformID == "1") then
																						tChildNode = new System.Windows.Forms.TreeNode(areaName,2,2);
																					else
																						tChildNode = new System.Windows.Forms.TreeNode(areaName,3,3);
																					endif;
																				else
																					tChildNode = new System.Windows.Forms.TreeNode(areaName,0,0);
																				endif;
																				endif;

																				tNinethLevelNode.Nodes.Add(tChildNode);
																				if DefaultSelectedName<>"" and areaName==DefaultSelectedName then
																					gPlantAreas.SelectedNode=tChildNode;
																					gPlantAreas.focus();
																				endif;	
																				bNodeFound = true;
																				Exit For;
																			endif;																			
																		Next;	
																	endif;
																Next;
															endif;
														Next;
													endif;
												Next;
											endif;
										Next;
									endif;
								Next;
							endif;
						Next;
					endif;
				Next;
			endif;
		Next;		
	Endif;
EndWhile;

gPlantAreas.ExpandAll();

gPlantAreas.EndUpdate();

_lastWriteTime = System.IO.File.GetLastWriteTime(_fullFileName).ToString();

_populateTreeView = false;
      
_fullFileName    _areaIconFileName   _appEngineIconFileName   _grWinPlatformIconFileName   _winPlatformIconFileName   gPlantAreas.ImageList   gPlantAreas.Nodes.Count   gPlantAreas.Nodes   DefaultSelectedName   gPlantAreas.SelectedNode	   _lastWriteTime
   _populateTreeView                                  4C  /C             [{SNHd5X@	     	  Arial                 	  	        %|fee62a82-b8b0-491b-9f63-f2228d2947e0_lastWriteTime  %|2064c01b-31bb-4115-8731-c30ed3a19e05
_fullFileName  %|6ce2e87e-3d00-4f66-b51c-0d8dc3eb9673_areaIconFileName  %|1bad1ccc-2eec-47c3-80f4-1f6823702efd_appEngineIconFileName  %|0fe4f6c0-3544-46cd-b5d9-b776ed42cc75_winPlatformIconFileName  %|d39ac3d0-39ea-44f7-ad2a-0d686150ff12_grWinPlatformIconFileName  %|62841e25-2d79-4c21-905f-05b20e632ec1SelectedName  %|acef97a9-a8a1-443f-a886-a2bdd9b34ba7DefaultSelectedName     gPlantAreas 	  	           k e UQ K_     